<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">

    <!-- <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Firmid')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-firmid" data-rule="required" class="form-control" name="row[firmid]" type="number" value="0">
        </div>
    </div> -->
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">
            调出库位/商品:
        </label>
        <div class="form-inline" data-toggle="cxselect" data-selects="first,two,three">
            <div class="col-xs-12 col-sm-8">
                <select id="one" class="first form-control" name="row[out_warehouse_id]" data-url="ykjp/inventory/transfer/warehouse">
                    <option value="" selected=""></option>
                </select>
                <select id="two" class="two form-control" name="row[out_partition_id]" data-url="ykjp/inventory/transfer/partition" data-query-name="id">
                    <option value="" selected=""></option>
                </select>
                <select id="three" class="three form-control" name="row[product_id]" data-url="ykjp/inventory/transfer/product" data-query-name="id" onchange="get_out_before_num()">
                    <option value="" selected=""></option>
                </select>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Out_before_num')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-out_before_num" readonly="readonly" data-rule="required" class="form-control" name="row[out_before_num]" type="number">
        </div>
    </div>
    <div class="form-group" id="e-select" style="display: none">
        <label class="control-label col-xs-12 col-sm-2">
            调入库位:
        </label>
        <div class="form-inline" data-toggle="cxselect" data-selects="firstx,twox">
            <div class="col-xs-12 col-sm-8">
                <select id="onex" class="firstx form-control" name="row[e_warehouse_id]" data-url="ykjp/inventory/transfer/warehouse">
                    <option value="" selected=""></option>
                </select>
                <select id="twox" class="twox form-control" name="row[e_partition_id]" data-url="ykjp/inventory/transfer/partition" data-query-name="id" onchange="get_e_before_num()">
                    <option value="" selected=""></option>
                </select>
            </div>
        </div>
    </div>
    <div class="form-group" id="e-show" style="display: none">
        <label class="control-label col-xs-12 col-sm-2">{:__('E_before_num')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-e_before_num" readonly="readonly" data-rule="required" class="form-control" name="row[e_before_num]" type="number">
        </div>
    </div>
    <!-- <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Out_warehouse_id')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-out_warehouse_id" data-rule="required" data-source="out/warehouse/index" class="form-control selectpage" name="row[out_warehouse_id]" type="text" value="">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Out_partition_id')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-out_partition_id" data-rule="required" data-source="out/partition/index" class="form-control selectpage" name="row[out_partition_id]" type="text" value="">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('E_warehouse_id')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-e_warehouse_id" data-rule="required" data-source="e/warehouse/index" class="form-control selectpage" name="row[e_warehouse_id]" type="text" value="">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('E_partition_id')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-e_partition_id" data-rule="required" data-source="e/partition/index" class="form-control selectpage" name="row[e_partition_id]" type="text" value="">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Product_id')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-product_id" data-rule="required" data-source="ykjp/product/index" class="form-control selectpage" name="row[product_id]" type="text" value="">
        </div>
    </div> -->
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Number')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-number" data-rule="required" class="form-control" name="row[number]" type="number">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Remark')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-remark" class="form-control" name="row[remark]" type="text">
        </div>
    </div>
    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
        </div>
    </div>
</form>
<script type="text/javascript">

    //获取调出前数量
    function get_out_before_num() {
        var warehouse_id = document.querySelector('#one').value  //仓库ID
        var partition_id = document.querySelector('#two').value  //库区ID
        var product_id = document.querySelector('#three').value  //产品ID
        $.ajax({
            url: 'ykjp/inventory/transfer/get_num',
            data: {
                'warehouse_id': warehouse_id,
                'partition_id': partition_id,
                'product_id': product_id
            },
            success: function (data, textStatus, xhr) {
                data = data.data
                if (data != null && data != '') {
                    $('#c-out_before_num').val(data.inventory)

                } else {
                    $('#c-out_before_num').val()
                }
                $("#e-select").css('display', 'block')
                $("#e-show").css('display', 'block')
            },
            error: function (xhr, textStatus, error) {

            }
        });
    }

    //获取调入前数量
    function get_e_before_num() {
        var warehouse_id = document.querySelector('#onex').value  //仓库ID
        var partition_id = document.querySelector('#twox').value  //库区ID
        var product_id = document.querySelector('#three').value  //产品ID
        if (product_id == null || product_id == '') {
            alert('请先选择商品！')
            return false
        }
        $.ajax({
            url: 'ykjp/inventory/transfer/get_num',
            data: {
                'warehouse_id': warehouse_id,
                'partition_id': partition_id,
                'product_id': product_id
            },
            success: function (data, textStatus, xhr) {
                data = data.data
                if (data != null && data != '') {
                    $('#c-e_before_num').val(data.inventory)
                } else {
                    $('#c-e_before_num').val(0)
                }
            },
            error: function (xhr, textStatus, error) {

            }
        });
    }
</script>
